﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;
using Castle.ActiveRecord;
using NHibernate;
using NHibernate.Criterion;

namespace ZdSoft.Model
{
    [ActiveRecord]
    public class Role:EntityBase
    {
        /// <summary>
        /// 角色名
        /// </summary>
        [Property(NotNull=true,Length=20)]
        [Required(ErrorMessage="不能为空")]
        [StringLength(20,ErrorMessage="不能超过20个字符")]
        [Display(Name="名称")]
        public string RoleName { get; set; }

        /// <summary>
        /// 确认是否激活，默认为true
        /// </summary>
        [Property(NotNull=true)]
        [Required]
        [Display(Name="激活")]
        public bool IsActive { get; set; }

        /// <summary>
        /// 当前角色拥有的用户
        /// </summary>
        [HasAndBelongsToMany(typeof(User),
            Table="User_Role",
            ColumnKey="RoleID",
            Inverse=false,
            ColumnRef="UserID",
            Lazy=true)]
        public IList<User> Users { get; set; }

        /// <summary>
        /// 当前角色拥有的系统功能
        /// </summary>
        [HasAndBelongsToMany(typeof(SystemFunction),
            Table = "Role_SystemFunction",
            ColumnKey = "RoleID",
            ColumnRef = "SystemFunctionID",
            Lazy = false)]
        public IList<SystemFunction> SystemFunctions { get; set; }

        #region 扩展属性，用于非ORM映射
        public bool IsChecked { get; set; }

        #endregion
    }
}
